package com.cloudptt.wp.ui.message;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.cloudptt.api.comm.CauseCont;
import com.cloudptt.api.comm.CommDlg;
import com.cloudptt.api.comm.FileOperation;
import com.cloudptt.api.product.Product;
import com.cloudptt.api.product.ProductConst;
import com.cloudptt.api.product.config.msg.MsgConfig;
import com.cloudptt.api.product.func.message.MsgListener;
import com.cloudptt.api.product.log.Log;
import com.cloudptt.api.product.operator.MsgOperator;
import com.cloudptt.wp.R;
import com.cloudptt.wp.ScreenManager;
import com.cloudptt.wp.SysApplication;
import com.cloudptt.wp.ui.message.adapter.IDownload;
import com.cloudptt.wp.ui.message.adapter.SessionAdapter;
import com.cloudptt.wp.ui.views.EditLayout;
import com.cloudptt.wp.ui.views.PTTLayout;
import com.cloudptt.wp.ui.views.listener.CustomListener;
import com.cloudptt.wp.ui.views.listener.EditLyChangeListener;
import com.mcptt.comm.CommonFunc;
import com.mcptt.config.body.info.mcdata.FileMataInfo;
import com.mcptt.config.body.info.mcdata.McdataInfoBody;
import com.mcptt.config.model.McIdInfo;
import com.mcptt.db.loader.msg.SessionFuncListLoader;
import com.mcptt.db.loader.msg.SessionListLoaderCb;
import com.mcptt.db.model.AddrInfo;
import com.mcptt.db.model.SessionInfo;
import com.mcptt.http.operator.IHttpOpCb;
import com.mcptt.http.operator.file.OnDownloadListener;
import com.mcptt.http.operator.file.OnUploadListener;

import java.io.File;
import java.util.List;


public class SessionFuncActivity extends Activity implements MsgListener,SessionListLoaderCb, View.OnClickListener, AdapterView.OnItemSelectedListener,CustomListener,EditLyChangeListener,IHttpOpCb,OnUploadListener, OnDownloadListener, IDownload {

	private static final String TAG = "SessionActivity";
	public static final String KEY = "funcList";
//	private static final int UPLOAD = 1;
//	private static final int UPLOAD_FINISH = 2;

	private static final int REQUEST_CODE_CHOOSE_PIC = 0;
	private static final int REQUEST_CODE_TAKE_PHOTO = 1;


	private AddrInfo peerAddrInfo;
	private MsgOperator operator = null;
	private EditText dstEt;
	private Spinner srcSpinner;
	private Button bindBtn;
	private ListView msgListView = null;
	private McIdInfo mcInfo = null;
	private String curFuncNum = null;
	private SessionAdapter mAdapter;
	private MsgConfig config = null;

	private EditLayout editLayout = null;
	private PTTLayout mPttLayout;

	private String curFileMetaData = "";
	private long size = 0;

	//	private String mTempPhotoPath;
	//	private Uri imageUri;
	private ProgressDialog dlg;
	private String[] funcNumArr = new String[0];
	private boolean isBinded = false;
//	private List<FuncNumOb> funcNumObList = new Vector<>();
	private String localPath = null;

	public void onCreate(Bundle savedInstanceState){

		Window window = getWindow();
		window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
		window.setStatusBarColor(getResources().getColor(R.color.app_theme_color_primary));

		super.onCreate(savedInstanceState);

		funcNumArr = getIntent().getStringArrayExtra(SessionFuncActivity.KEY);
		Log.i(TAG,"onCreate funcNumArr =  "+ funcNumArr);
		initView();

		initOrUpdateLoader(false);

		ScreenManager.getScreenManager( ).pushActivity( this );
	}

	private void initOrUpdateLoader(boolean isUpdate)
	{
		Log.v( TAG, "initOrUpdateLoader " + isUpdate);
		SysApplication app = ((SysApplication) getApplicationContext());
		Product product = app.getProduct();
		product.setMsgListener(this,peerAddrInfo);
		this.config = product.getSysConfig().getMsgConfig();
		this.operator = (MsgOperator)product.getOperator(ProductConst.Func_Msg);
		this.mcInfo = product.getMcpttLoginInfo().getMcIdInfo();
//		SessionFuncListLoader loader = this.operator.getFuncSessionListLoader(this,this);
	}


	private void initView()
	{
		setContentView(R.layout.activity_session_func);

		ImageView iv = (ImageView) findViewById(R.id.back_up_icon);
		iv.setOnClickListener(this);
		TextView tv = (TextView) findViewById(R.id.title);
		tv.setText(R.string.func_title_msg);
//		if(peerAddrInfo != null)
//		{
//			String name = peerAddrInfo.getDscp();
//			tv.setText(name);
//		}
//
//		if(peerAddrInfo != null)
//		{
//			String dscp = peerAddrInfo.getDscp();
//			//			title.setText(dscp);
//		}

		dstEt = (EditText) findViewById(R.id.dstEt);
		srcSpinner = (Spinner) findViewById(R.id.srcSpinner);
		srcSpinner.getBackground().setColorFilter(getResources().getColor(R.color.app_theme_color_primary), PorterDuff.Mode.SRC_ATOP);
		ArrayAdapter<String> funcAdapter = new ArrayAdapter<>(this, R.layout.item_select, funcNumArr);
		srcSpinner.setAdapter(funcAdapter);
		String str = getString(R.string.func_select_func_num);
		srcSpinner.setPrompt(str);
		srcSpinner.setSelection(0);
		srcSpinner.setOnItemSelectedListener(this);
		curFuncNum = srcSpinner.getSelectedItem().toString();
//		srcEt.setOnTouchListener(this);//.setOnClickListener(this);
		bindBtn = (Button) findViewById(R.id.bindBtn);
		bindBtn.setOnClickListener(this);

		msgListView = (ListView) findViewById(R.id.msgListView);
		msgListView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);

		msgListView.setOnTouchListener(new OnTouchListener() {
			@Override
			public boolean onTouch(View arg0, MotionEvent arg1) {
				//imm.hideSoftInputFromWindow(contentEditText.getWindowToken(), 0); 
				//				contentEditText.clearFocus();
				if(editLayout.isShown()){
					editLayout.clearState();
				}
				if(mAdapter != null) {
					mAdapter.clearSelect();
				}
				//				mExpandFuncLayout.setVisibility(View.GONE);
				return false;
			}
		});

		editLayout  = (EditLayout)findViewById(R.id.bottom_edit_layout);

		mPttLayout  = (PTTLayout)findViewById(R.id.bottom_ptt_layout);
		mPttLayout.setCustomView(R.drawable.switch_to_editlayout, this);
	}

	@Override
	protected void onResume() {
		super.onResume();
	}


	@Override
	protected void onDestroy()
	{
		super.onDestroy();
	}

	private void showContactDialog(final String[] arg ,final SessionInfo sInfo)
	{
		AddrInfo info = sInfo.getPeerAddrInfo();
		String name = info.getName();
		new AlertDialog.Builder(this).setTitle(name).setItems(arg,
				new DialogInterface.OnClickListener(){
					public void onClick(DialogInterface dialog, int which)
					{
						switch(which)
						{
							case 0:
								SysApplication app = ((SysApplication) getApplicationContext());
								Product product = app.getProduct();
								MsgOperator operator = (MsgOperator)product.getOperator(ProductConst.Func_Msg);
								boolean isSuc = operator.delSession(sInfo);
								Log.d(TAG, "operator.delSession isSuc = " + isSuc);
								if(isSuc)
								{
									initOrUpdateLoader(true);
								}
								break;
							case 1:
								String content  = sInfo.getContent();
								ClipboardManager cmb = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
								cmb.setText(content.trim());
								break;
						}
					}
				}).show();
	}

	//	private void showOperateDlg(final String[] arg)
	//	{
	//		new AlertDialog.Builder(this).setItems(arg,
	//				new DialogInterface.OnClickListener(){
	//			public void onClick(DialogInterface dialog, int which)
	//			{
	//				switch(which)
	//				{
	//				case 0:
	//					ClipboardManager cmb = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
	//					String content = cmb.getText().toString().trim();
	//					contentEditText.append(content);
	//					break;
	//				}
	//			}
	//		}).show();
	//	}

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		super.onBackPressed();
		SessionFuncActivity.this.setResult(RESULT_OK);
		SessionFuncActivity.this.finish();
	}

	@Override
	public void onLoadFinished(List<SessionInfo> list) {
		// TODO Auto-generated method stub
		Log.debug(this.getClass(),"onLoadFinished list = " + list);
		mAdapter = new SessionAdapter(this, peerAddrInfo,list,this,true);
		msgListView.setAdapter(mAdapter);
		msgListView.setSelection(mAdapter.getCount());
		//		if( null == newMessage ){
		////			contentEditText.setText( "" );
		//		}
	}

	@Override
	public void onLoaderReset() {
		// TODO Auto-generated method stub
		Log.d(TAG,"onLoaderReset");
		msgListView.setAdapter(null);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
			case R.id.back_up_icon:
				this.finish();
				overridePendingTransition( R.anim.in_from_left, R.anim.out_to_right );
				break;
			case R.id.bindBtn:
				String dstNum = dstEt.getText().toString();
				String srcNum = srcSpinner.getSelectedItem().toString();
				Log.debug(this.getClass(),"onClick dstNum = " + dstNum + " srcNum = " + srcNum);
				if(dstNum == null
						|| dstNum.equals(""))
				{
					CommDlg.showToast(SessionFuncActivity.this,R.string.func_dst_num_check);
					return;
				}
				if(srcNum == null
						|| srcNum.equals(""))
				{
					CommDlg.showToast(SessionFuncActivity.this,R.string.func_src_num_check);
					return;
				}
				int type = AddrInfo.UserType_User;
				if(dstNum.equals("210")
					|| dstNum.equals("299"))
				{
					dstNum = "50"+ dstNum;
					type = AddrInfo.GroupType_Normal;
				}
				peerAddrInfo = new AddrInfo(type,dstNum,dstNum,0);
				editLayout.setListener(peerAddrInfo,this);
//				if(!peerAddrInfo.isGroupType()){
					editLayout.setSwitchPTTEnable(false);
//				}
				isBinded = !isBinded;
				if(isBinded)
				{
					dstEt.setEnabled(false);
					srcSpinner.setEnabled(false);
					bindBtn.setText(R.string.func_unbind);
				}
				else
				{
					dstEt.setEnabled(true);
					srcSpinner.setEnabled(true);
					bindBtn.setText(R.string.func_bind);
				}
				break;
			default:
				break;
		}
	}


//	@Override
//	public void onClick(DialogInterface dialog, int index) {
//		if(index < funcNumArr.length) {
//			curFuncNum = funcNumArr[index];
//			if(curFuncNum != null) {
//				srcEt.setText(curFuncNum);
//			}
//		}
//	}



	@Override
	public void receiveMsg() {
		// TODO Auto-generated method stub
		initOrUpdateLoader(true);
	}

	@Override
	public void customFunc() {
		// TODO Auto-generated method stub
		//editLayout.showBottomLayout(EditLayout.SHOW_EDIT);
		editLayout.setVisibility(View.VISIBLE);
		mPttLayout.setVisibility(View.GONE);

	}

	@Override
	public void onSwitchPttLy() {
		// TODO Auto-generated method stub
		editLayout.setVisibility(View.GONE);
		mPttLayout.setVisibility(View.VISIBLE);
	}
	@Override
	public void onSendMsg(int contentType, String contentStr)
	{
		Log.d(TAG,"onSendMsg msgType = "+ contentType + " contentStr = "+ contentStr);
		if(!isBinded)
		{
			CommDlg.showToast(SessionFuncActivity.this,R.string.func_bind_dst_num);
			return;
		}
		if(peerAddrInfo == null)
		{
			CommDlg.showToast(SessionFuncActivity.this.getApplicationContext( ), getResources().getString(R.string.please_pickup_user));
			return;
		}
		if(curFuncNum == null)
		{
			CommDlg.showToast(SessionFuncActivity.this,R.string.func_src_num_check);
			return;
		}
		AddrInfo addrInfo = new AddrInfo(AddrInfo.GroupType_Normal,curFuncNum,curFuncNum,AddrInfo.DEFAULT_ATTR);
		int reqType = config.getDispositionReqType(false);
		SessionInfo session = new SessionInfo(peerAddrInfo, addrInfo, contentType,SessionInfo.Direction_Type_Send,contentStr,reqType);
		Log.d(TAG,"sendMsgBySip MessageInfo = "+ session);
		if(this.operator != null)
		{

			String peerAddrId = peerAddrInfo.getAddrId();
			int result = this.operator.sendMcDataMessage(session);
			Log.d(TAG,"sendMsgBySip sendMessage result = "+ result);
			if(result != CauseCont.OperateCheck_Suc)
			{
				String errStr = CauseCont.getOperateCheckErrStr(result, SessionFuncActivity.this);
				CommDlg.showToast(SessionFuncActivity.this,errStr);
			}
			else
			{
				//					contentEditText.setText("");
				initOrUpdateLoader(true);
			}

		}
	}

	@Override
	public void doAction(int subFunc) {
		// TODO Auto-generated method stub
		Intent funcIntent;
		switch (subFunc) {
			case EditLayout.CHOOSE_PIC:
				funcIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
				funcIntent.setType("image/*");
				startActivityForResult(funcIntent, REQUEST_CODE_CHOOSE_PIC);
				break;

			case EditLayout.OPEN_CAMERA:
				//			Intent intent = new Intent();
				//			intent.setClass(SessionActivity.this, CameraShowActivity.class);
				//			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
				//			startActivity(intent);
				Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
				startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO);

				break;

			default:
				break;
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		Log.v( TAG, "onActivityResult:requestCode:" + requestCode +" resultCode:" + resultCode);

		if(resultCode != RESULT_OK){
			return;
		}

		switch (requestCode) {
			case REQUEST_CODE_CHOOSE_PIC:
				if(data.getData() == null){
					return;
				}
				Uri selectedImage = data.getData();
				String[] filePathColumn = {MediaStore.Images.Media.DATA};
				Cursor cursor = getContentResolver().query(selectedImage,
						filePathColumn, null, null, null);
				assert cursor != null;
				cursor.moveToFirst();
				int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
				String picturePath = cursor.getString(columnIndex);
				cursor.close();
				File file = new File(picturePath);
				curFileMetaData = FileMataInfo.toMetaData(file,0);
				size = file.length();

				showUploadDialog(file,size);
				break;

			case REQUEST_CODE_TAKE_PHOTO:
				if (resultCode == Activity.RESULT_OK)
				{
					String sdStatus = Environment.getExternalStorageState();
					if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // 检测sd是否可用
						return;
					}
					Bundle bundle = data.getExtras();
					Bitmap bitmap = (Bitmap) bundle.get("data");//
					String path = FileOperation.getFilePath(SessionInfo.Filetype_Pic);
					File dir = new File(path);
					if (!dir.exists()) {
						dir.mkdirs();
					}

					//			String fileName = generateName();
					String name = generateName();
					file = new File(dir, name);
					FileOperation.saveImgFile(file, bitmap);
					curFileMetaData = FileMataInfo.toMetaData(file,0);
					long size = file.length();
					//Toast.makeText(this, "Img fileName = " + file, Toast.LENGTH_SHORT).show();
					//				uploadFile(file);
					showUploadDialog(file,size);
				}
				break;

			default:
				break;
		}
	}
	@Override
	public void uploadVoiceMsg(String voiceMsgPath)
	{
		File file = new File(voiceMsgPath);
		String fileName = file.getName();
		curFileMetaData = FileMataInfo.toMetaData(file,0);
		long size = file.length();
		Log.d(TAG, "audioRecorderButton onFinish size = " + size + " fileName = " + fileName);
		showUploadDialog(file,size);
	}
	private void uploadFile(File file,long len)
	{
		Log.d(TAG, "uploadFile file = " + file);
		if(!file.exists())
		{
			Log.d(TAG, "uploadFile file no exists pic = " + file);
			Toast.makeText(this, "file is no exist " + file, Toast.LENGTH_SHORT).show();
			return;
		}
		if(curFuncNum == null)
		{
			CommDlg.showToast(SessionFuncActivity.this,R.string.func_src_num_check);
			return;
		}

		SysApplication app = ((SysApplication) getApplicationContext());
		Product product = app.getProduct();
		if(product != null)
		{
			String peerMcdataId = peerAddrInfo.getMcxId();
			String url = product.getSysConfig().getFileSvrUrl();
			if(url != null
					&& !url.trim().equals("")) {
				if (operator == null) {
					this.operator = (MsgOperator) product.getOperator(ProductConst.Func_Msg);
				}
				String msgType = SessionInfo.MsgType_Desc_Oto_FD;
				if (peerAddrInfo.isGroupType()) {
					msgType = SessionInfo.MsgType_Desc_Group_FD;
				}
				String clientId = this.mcInfo.getClientId();
				McdataInfoBody body = new McdataInfoBody(SessionInfo.Type_Func,msgType, peerMcdataId, curFuncNum, clientId);
				String infoBody = body.toString();
				operator.uploadFile(url, file, len, this, this, infoBody);
			}
			else {
				CommDlg.showToast(SessionFuncActivity.this,R.string.fd_url_null);
			}
		}
	}
	@Override
	public void onOpResult(int id,boolean isSuc,SessionInfo info,int cause,String fileUrl,File file)
	{
		Log.d(TAG, "onOpResult isSuc = " + isSuc + " fileUrl = " + fileUrl + " file = " + file);
		if(IHttpOpCb.Id_UpLoad == id) {
			String result = " failed";
			if (isSuc) {
				result = " successful";
			}
			Toast.makeText(this, "file upload " + result + fileUrl, Toast.LENGTH_SHORT).show();
			if(isSuc)
			{
				procUploadSuc(fileUrl,file);
			}
		}
		else if(IHttpOpCb.Id_DownLoad == id)
		{
			Log.debug(getClass(), "onDownloading isSuc = " + isSuc);
			String result = " failed";
			if (isSuc) {
				result = " successful";
			}
			Toast.makeText(this, "file download " + result + localPath, Toast.LENGTH_SHORT).show();
		}
		if(!isSuc
			&& dlg != null)
		{
			dlg.dismiss();
		}
	}
	private void procUploadSuc(String fileUrl,File file)
	{
		AddrInfo addrInfo = new AddrInfo(AddrInfo.GroupType_Normal,curFuncNum,curFuncNum,AddrInfo.DEFAULT_ATTR);
		int reqType = config.getDispositionReqType(true);
		SessionInfo session = new SessionInfo(peerAddrInfo, addrInfo, SessionInfo.ContentType_FileURL, SessionInfo.Direction_Type_Send, fileUrl,file.toString(), curFileMetaData,reqType);
		Log.d(TAG, "procUploadSuc MessageInfo = " + session);
		if (operator != null) {
			int result = operator.sendMcDataMessage(session);
			Log.d(TAG,"procUploadSuc sendMessage result = "+ result);
			if(result != CauseCont.OperateCheck_Suc)
			{
				String errStr = CauseCont.getOperateCheckErrStr(result, SessionFuncActivity.this);
				CommDlg.showToast(SessionFuncActivity.this,errStr);
			}
			else
			{
				initOrUpdateLoader(true);
			}
		}
	}

//	public void onOpResult(boolean isSuc) {
//		// TODO Auto-generated method stub
//		String result = " failed";
//		if(isSuc)
//		{
//			result = " successful";
//		}
//		//Toast.makeText(this, "file upload " + result, Toast.LENGTH_SHORT).show();
//	};

	@Override
	public void onProgress(long bytesRead, long contentLength, boolean done,String remoteFilePath,long len) {
		// TODO Auto-generated method stub
		Log.debug(getClass(), "bytesRead:" + bytesRead);
		Log.debug(getClass(), "contentLength:" + contentLength);
		Log.debug(getClass(), "done:" + done);
		if(done)
		{
//			onSendMsg(SessionInfo.ContentType_File,remoteFilePath);
			dlg.dismiss();
		}
		else
		{
			float value = ((float)bytesRead)/contentLength;
			Log.debug(getClass(), "onProgress value:" + value);
			int progress = (int)(value * 100);
			Log.debug(getClass(), "onProgress progress:" + progress);
			dlg.setProgress(progress);
		}
	};

	private String generateName() {
		return CommonFunc.getDateAndTime2() + ".jpg";
	}

	public void showUploadDialog(File file,long len)
	{

		dlg = new ProgressDialog(SessionFuncActivity.this);

		dlg.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
		dlg.setIcon(android.R.drawable.progress_indeterminate_horizontal);
		String str = this.getString(R.string.fd_upload);
		dlg.setMessage(str);
		dlg.setCancelable(false);
		dlg.show();

		uploadFile(file,len);
	}


	@Override
	public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
		curFuncNum = srcSpinner.getSelectedItem().toString();
	}

	@Override
	public void onNothingSelected(AdapterView<?> parent) {

	}
	public void showDownloadDialog(SessionInfo info)
	{

		dlg = new ProgressDialog(this);

		dlg.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
		dlg.setIcon(android.R.drawable.progress_indeterminate_horizontal);
		String str = getString(R.string.fd_download);
		dlg.setMessage(str);
		dlg.setCancelable(false);
		dlg.show();

		downloadFile(info);
	}

	private void downloadFile(SessionInfo info)
	{
		SysApplication app = ((SysApplication) getApplicationContext());
		Product product = app.getProduct();
		final String path = info.getContent();
		String fileMataStr = info.getFileMetaData();
		Log.debug(getClass(), "downloadFile path = " + path + " fileMataStr = " + fileMataStr);
		FileMataInfo fileMataInfo = FileMataInfo.parse(fileMataStr);
		String name = fileMataInfo.getFileName();
		Log.debug(getClass(), "downloadFile name = " + name);

		if (product != null) {
			MsgOperator operator = (MsgOperator) product.getOperator(ProductConst.Func_Msg);
			String localPath = FileOperation.getFilePath(SessionInfo.Filetype_File);
			if (FileOperation.isPicture(name)) {
				localPath = FileOperation.getFilePath(SessionInfo.Filetype_Pic);
			}
//						else if(Common.isAudio(name))
//						{
//							localPath = FileOperation.getFilePath(SessionInfo.Filetype_Video);
//						}

			Log.debug(getClass(), "downloadFile localPath = " + localPath);
//						File file = new File(path);
//						String name = file.getName();
			Log.debug(getClass(), "downloadFile name = " + name);
			operator.downloadFile(info,path, name, this, this);
		}
	}

	@Override
	public void onDownloading(int progress, String localPath) {
		// TODO Auto-generated method stub
		Log.debug(getClass(), "onDownloading progress = " + progress + " localPath = " + localPath);
		this.localPath = localPath;
		if(progress >= 100)
		{
//			onSendMsg(SessionInfo.ContentType_File,remoteFilePath);
			dlg.dismiss();
		}
		else
		{
			Log.debug(getClass(), "onProgress progress:" + progress);
			dlg.setProgress(progress);
		}
	}
}
